<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="../common/css-top.jsp"></jsp:include>
</head>
<body class="hold-transition skin-purple sidebar-mini">
<div class="wrapper">
    <!-- 页面头部 -->
    <jsp:include page="../common/header.jsp"></jsp:include>
    <!-- 页面头部 /-->
    <!-- 导航侧栏 -->
    <jsp:include page="../common/aside.jsp"></jsp:include>
    <!-- 导航侧栏 /-->
    <div class="content-wrapper">
        <!-- 内容头部 -->
        <section class="content-header">
            <h1>
                订单管理 <small>订单列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="../main.jsp"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">订单管理</a></li>
                <li class="active">订单列表</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!-- .box-body -->
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">列表</h3>
                </div>

                <div class="box-body">

                    <!-- 数据表格 -->
                    <div class="table-box">

                        <!--工具栏-->
                        <div class="pull-left">
                            <div class="form-group form-inline">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-default" title="新建"
                                            onclick="location.href='product-add.jsp'">
                                        <i class="fa fa-file-o"></i> 新建
                                    </button>
                                    <button type="button" class="btn btn-default" title="删除">
                                        <i class="fa fa-trash-o"></i> 删除
                                    </button>
                                    <button type="button" class="btn btn-default" title="开启">
                                        <i class="fa fa-check"></i> 开启
                                    </button>
                                    <button type="button" class="btn btn-default" title="屏蔽">
                                        <i class="fa fa-ban"></i> 屏蔽
                                    </button>
                                    <button type="button" onclick="location.reload()" class="btn btn-default" title="刷新">
                                        <i class="fa fa-refresh"></i> 刷新
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="box-tools pull-right">
                            <div class="has-feedback">
                                <input type="text" class="form-control input-sm"
                                       placeholder="搜索"> <span
                                    class="glyphicon glyphicon-search form-control-feedback"></span>
                            </div>
                        </div>
                        <!--工具栏/-->

                        <!--数据列表-->
                        <table id="dataList"
                               class="table table-bordered table-striped table-hover dataTable">
                            <thead>
                            <tr>
                                <th class="" style="padding-right: 0px;"><input
                                        id="selall" type="checkbox" class="icheckbox_square-blue">
                                </th>
                                <th class="sorting_asc">ID</th>
                                <th class="sorting_desc">订单编号</th>
                                <th class="sorting_asc sorting_asc_disabled">产品名称</th>
                                <th class="sorting_desc sorting_desc_disabled">金额</th>
                                <th class="sorting">下单时间</th>
                                <th class="text-center sorting">订单状态</th>
                                <th class="text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            <c:forEach items="${pageInfo.list}" var="orders">

                                <tr>
                                    <td><input name="ids" type="checkbox"></td>
                                    <td>${orders.id }</td>
                                    <td>${orders.orderNum }</td>
                                    <td>${orders.product.productName }</td>
                                    <td>${orders.product.productPrice }</td>
                                    <td>${orders.orderTimeStr }</td>
                                    <td class="text-center">${orders.orderStatusStr }</td>
                                    <td class="text-center">
                                        <button type="button" class="btn bg-olive btn-xs"
                                                onclick="selectOrdersDetailById('${orders.id}',0)">
                                            详情
                                        </button>
                                        <button type="button" onclick="selectOrdersDetailById('${orders.id}',1)" class="btn bg-olive btn-xs">编辑</button>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                        <!--数据列表/-->

                    </div>
                    <!-- 数据表格 /-->
                </div>
                <!-- /.box-body -->


                <!-- 页码box-footer-->
                <div class="box-footer">
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            总共${pageInfo.pages} 页，共${pageInfo.total} 条数据。 每页
                            <select id="changePageSize" class="form-control" onchange="changePageSize()">
                                <option  ${pageInfo.pageSize==5 ?'selected':''}>5</option>
                                <option  ${pageInfo.pageSize==10 ?'selected':''}>10</option>
                                <option  ${pageInfo.pageSize==15 ?'selected':''}>15</option>
                            </select> 条
                        </div>
                    </div>

                    <div class="box-tools pull-right">
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}/orders/findAll.do?page=1&pageSize=5"
                                   aria-label="Previous">首页</a>
                            </li>
                            <%--当前页为首页时，上一页按钮禁用--%>
                            <li><a
                                    <c:if test="${pageInfo.pageNum != pageInfo.firstPage}">
                                        href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.prePage}&pageSize=${pageInfo.pageSize}"
                                    </c:if>
                                    <c:if test="${pageInfo.pageNum == pageInfo.firstPage}">
                                        href="javascript:void(0)" class="disabled"</c:if> >上一页</a>
                            </li>
                            <!-- foreach 从 1 开始 到 总页数结束  遍历输出 -->

                            <c:forEach begin="1" end="${pageInfo.pages }" varStatus="status">
                                <li>
                                    <a href="${pageContext.request.contextPath}/orders/findAll.do?page=${status.count}&pageSize=${pageInfo.pageSize}"
                                        
                                            <c:if test="${status.count == pageInfo.pageNum}"> class="bg-gray" </c:if>
                                    >${status.count }</a>
                                </li>
                            </c:forEach>


                            <!-- 当前页为最后一页时href="javascript:void(0)" 禁用 a 标签的点击时间事件 
                                        当前页不是最后一页时请求url 中返回page=${pageInfo.nextPage } 当前页 -1
                                     -->
                            <li><a
                                    <c:if test="${pageInfo.pageNum == pageInfo.lastPage}">class="disabled"
                                    href="javascript:void(0)" </c:if>
                                    <c:if
                                            test="${pageInfo.pageNum != pageInfo.lastPage}">href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.nextPage}&pageSize=${pageInfo.pageSize}"
                            </c:if>
                            >下一页</a></li>
                            <li>
                                <a href="${pageContext.request.contextPath}/orders/findAll.do?page=${pageInfo.pages}&pageSize=${pageInfo.pageSize}"
                                   aria-label="Next">尾页</a>
                            </li>
                        </ul>
                    </div>

                </div>
                <!-- /.box-footer-->


            </div>
        </section>
        <!-- 正文区域 /-->
    </div>
    <!-- @@close -->
    <!-- 内容区域 /-->
    <jsp:include page="../common/css-bottom.jsp"></jsp:include>
</div>

<jsp:include page="../common/css-bottom-js.jsp"></jsp:include>
<script>
    function changePageSize() {
        //获取下拉框的值
        var pageSize = $("#changePageSize").val();

        //向服务器发送请求，改变没页显示条数
        location.href = "${pageContext.request.contextPath}/orders/findAll.do?page=1&pageSize="
            + pageSize;
    }

    $(document).ready(function () {
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });

    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }

    $(document).ready(function () {

        // 激活导航位置
        setSidebarActive("admin-datalist");

        // 列表按钮
        $("#dataList td input[type='checkbox']").iCheck({
            checkboxClass: 'icheckbox_square-blue',
            increaseArea: '20%'
        });
        // 全选操作
        $("#selall").click(function () {
            var clicks = $(this).is(':checked');
            if (!clicks) {
                $("#dataList td input[type='checkbox']").iCheck("uncheck");
            } else {
                $("#dataList td input[type='checkbox']").iCheck("check");
            }
            $(this).data("clicks", !clicks);
        });
    });

    //handleId为0，表示详情，若为1，代表编辑
    function selectOrdersDetailById(orderId,handleId) {
        location.href = '${pageContext.request.contextPath}/orders/findById.do?orderId='+orderId+'&handleId='+handleId;
    }
</script>
</body>

</html>